var webSiteUrl = 'http://ningde.59156.cn';
// var webSiteUrl = 'http://192.168.0.115:802';

var user_data = $api.getStorage('user');

if(user_data != null || Object.prototype.toString.call(user_data) !== '[object Undefined]'){

var id = $api.getStorage('user').id;
var is_login = 1;

}else{
	var is_login = 0;
}




function ajpush(){
	var did = api.deviceId;
    var ajpush = api.require('ajpush');
	if(api.systemType == "android"){
            ajpush.init(function(ret) {
                var param = {alias:did,tags:['user']};
                ajpush.bindAliasAndTags(param,function(rete) {
                    
                });
                ajpush.setListener(jpushListener);
               
            });
        }else if(api.systemType == "ios"){
            ajpush.setListener(jpushListener);
            var param = {alias:did,tags:['user']};
            ajpush.bindAliasAndTags(param,function(ret) {
                 
            });
           
        }
        
        function jpushListener(ret){
            
        }
}
	


function message(){
	if (is_login == 1) {
			var p = {uid:id};
	        api.ajax({
	            url:webSiteUrl+'/App/User/message',
	            method:'post',
	            data:{
	                values:p
	            }
	        },function(ret,err){
	             

	            if (ret.code == 200) {
	               var list = ret.data.message;
	              
	               var sid = api.deviceId;

	               html = '';
	               if (list != null) {
	                   for (var i=0 ; i < list.length ; i++) {

	                       if(list[i].see_status == 0){
	                       		var c = list[i].title;
	                            var s = {did:sid,content:c};
	                            api.ajax({
	                                url:webSiteUrl+'/App/public/jpush_send',
	                                method:'post',
	                                data:{
	                                    values:s
	                                }
	                            },function(ret,err){

	                            });
	                       }
	                    }
	                }

	               
	            }
	        });
		}
		
	}
	



